const httpInterceptor = {
  invoke(options) {
    // 添加token
    const token = uni.getStorageSync('uni_id_token')
    if (token) {
      options.header = {
        ...options.header,
        'x-token': token
      }
    }
    
    // 请求拦截
    return options
  },
  success(response) {
    // 如果token过期，尝试重新登录
    if (response.data.errCode === 'TOKEN_INVALID') {
      LoginManager.silentLogin()
    }
    return response
  }
}

uni.addInterceptor('request', httpInterceptor)
uni.addInterceptor('uploadFile', httpInterceptor)
